package org.example.controller;

import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.example.JavaBean.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.List;

/**
 * @Auther:Liu
 * @Testname:fourcontroller
 * @Date:2025/7/30 16:46
 */
@Slf4j
@Controller
@RequestMapping("/four")
public class fourcontroller {

    @RequestMapping("/a")
    public void a(HttpServletResponse response) throws IOException {
        log.info("用户访问了fourcontroller的a方法");
        response.setContentType("application/json;charset=utf-8");
        PrintWriter out = response.getWriter();
        out.println("Hellow!");
    }

    @RequestMapping("/b")
    @ResponseBody //返回结果，不是页面跳转
    public String b(){
        log.info("用户访问了fourcontroller的b方法");
        return "Hellow!";
    }

    @RequestMapping(value = "/c",produces = {"application/json;charset=utf-8"})
    @ResponseBody //返回结果，不是页面跳转
    public User c(){
        log.info("用户访问了fourcontroller的c方法");
        User user = new User();
        user.setId(1);
        user.setName("张三");
        user.setAge(29);
        user.setGender('女');
        return user;
    }

    @RequestMapping("/d")
    @ResponseBody //返回结果，不是页面跳转
    public List<User> d(){
        log.info("用户访问了fourcontroller的d方法");
        User user1 = new User(1,"张三",23,'男');
        User user2 = new User(2,"李四",29,'男');
        User user3 = new User(3,"王五",23,'男');
        User user4 = new User(4,"赵六",23,'男');
        List<User> list = Arrays.asList(user1, user2, user3, user4);
        return list;
    }
}
